﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WiTeach.Tools;

namespace WiTeach.MaterialManagement.View
{
    /// <summary>
    /// materialShow.xaml 的交互逻辑
    /// </summary>
    public partial class materialShow : Page
    {
        public materialShow()
        {
            InitializeComponent();
            // 修改页面背景主题
            ImageBrush brush = new ImageBrush();
            brush.Stretch = Stretch.Fill;
            brush.ImageSource = new BitmapImage(new Uri(App.backgroundImage, UriKind.RelativeOrAbsolute));
            this.Background = brush;
            getMaterialName();
            getMaterialNum();
            getMaterialImage();
        }

        private void backHomeButton_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.GetNavigationService(this).Navigate(new Uri("/WiTeach;component/CourseManagement/View/CourseIndex.xaml", UriKind.Relative));
        }

        private void backPreLevel(object sender, RoutedEventArgs e)
        {
            this.NavigationService.GoBack();
            //NavigationService.GetNavigationService(this).Navigate(new Uri("/WiTeach;component/ClassManagement/View/ClassStudyIndex.xaml", UriKind.Relative));
        }
        private void courselist_backmain_mouse_enter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 66;
            image.Width = 104;
        }
        private void courselist_backmain_mouse_leave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 60;
            image.Width = 98;
        }
        private void courselist_back_mouse_enter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 66;
            image.Width = 104;
        }
        private void courselist_back_mouse_leave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 60;
            image.Width = 98;
        }
        private void uv4_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string KEIL_Lic_path = System.Configuration.ConfigurationManager.AppSettings["app_KEIL_Lic"];
                Process uv4 = new Process();
                uv4.StartInfo.FileName = KEIL_Lic_path;
                uv4.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
                uv4.Start();
                uv4.WaitForExit();
                uv4.Close();
            }
            catch (Exception)
            {
            }

            //   System.Diagnostics.Process.Start(@KEIL_Lic_path);
        }

        private void progisp_Click(object sender, RoutedEventArgs e)
        {
            string progisp_path = System.Configuration.ConfigurationManager.AppSettings["app_progisp"];


            //     System.Diagnostics.Process.Start(@progisp_path);
            try
            {
                Process progisp = new Process();
                progisp.StartInfo.FileName = progisp_path;
                progisp.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
                progisp.Start();
                progisp.WaitForExit();
                progisp.Close();
                GC.Collect();
            }
            catch (Exception)
            {
            }

        }

        private void flymcu_Click(object sender, RoutedEventArgs e)
        {
            string flymcu_path = System.Configuration.ConfigurationManager.AppSettings["app_flymcu"];
            //          System.Diagnostics.Process.Start(@flymcu_path);
            try
            {
                Process flymcu = new Process();
                flymcu.StartInfo.FileName = flymcu_path;
                flymcu.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
                flymcu.Start();
                flymcu.WaitForExit();
                flymcu.Close();
                GC.Collect();
            }
            catch (Exception)
            {
            }

        }

        private void arduino_Click(object sender, RoutedEventArgs e)
        {
            string arduino_path = System.Configuration.ConfigurationManager.AppSettings["app_arduino"];
            //        System.Diagnostics.Process.Start(@arduino_path);
            try
            {
                Process arduino = new Process();
                arduino.StartInfo.FileName = arduino_path;
                arduino.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
                arduino.Start();
                arduino.WaitForExit();
                arduino.Close();
                GC.Collect();
            }
            catch (Exception)
            {
            }

        }
        private void scratch_Click(object sender, RoutedEventArgs e)
        {
            string scratch_path = System.Configuration.ConfigurationManager.AppSettings["app_scratch"];
            //        System.Diagnostics.Process.Start(@arduino_path);
            try
            {
                Process scratch = new Process();
                scratch.StartInfo.FileName = scratch_path;
                scratch.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
                scratch.Start();
                scratch.WaitForExit();
                scratch.Close();
                GC.Collect();
            }
            catch (Exception)
            {
            }

        }
        private void course_scratch_mouse_enter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 54;
            image.Width = 60;
        }
        private void course_scratch_mouse_leave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 48;
            image.Width = 54;
        }
        private void sa_Click(object sender, RoutedEventArgs e)
        {
            string sa_path = System.Configuration.ConfigurationManager.AppSettings["app_S4A15"];
            Process sa = new Process();
            try
            {
                sa.StartInfo.FileName = sa_path;
                Console.WriteLine("sa_path" + sa_path);
                sa.Start();
                sa.WaitForExit();
                sa.Close();
                GC.Collect();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }

        private void course_logout_mouse_enter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 35;
            image.Width = 74;
        }
        private void course_logout_mouse_leave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 28;
            image.Width = 68;
        }
        private void course_keil_mouse_enter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 56;
            image.Width = 59;
        }
        private void course_keil_mouse_leave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 46;
            image.Width = 49;
        }
        private void course_arduino_mouse_enter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 54;
            image.Width = 60;
        }
        private void course_arduino_mouse_leave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 48;
            image.Width = 54;
        }
        private void course_flymcu_mouse_enter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 52;
            image.Width = 60;
        }
        private void course_flymcu_mouse_leave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 48;
            image.Width = 54;
        }
        private void course_progisp_mouse_enter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 52;
            image.Width = 59;
        }
        private void course_progisp_mouse_leave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 48;
            image.Width = 54;
        }
        private void course_s4a_mouse_enter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 53;
            image.Width = 59;
        }
        private void course_s4a_mouse_leave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 48;
            image.Width = 54;
        }

        DataTable materialTable;
        private void getMaterialName()
        {
            //string sql = "select * from material_type_table where MaterialType_ID = 1";
            //DataTable courseTable = SqlHelper.ExecuteDataTable(sql,new MySqlParameter[]{new MySqlParameter("@Lesson_ID",Lesson_ID)});

            string sql1 = "select MaterialType_Name from material_type_table where MaterialType_ID = " + 1;
            materialTable = SqlHelper.ExecuteDataTable(sql1);
            materialOne.Content = materialTable.Rows[0][0].ToString();

            string sql2 = "select MaterialType_Name from material_type_table where MaterialType_ID = " + 2;
            materialTable = SqlHelper.ExecuteDataTable(sql2);
            materialTwo.Content = materialTable.Rows[0][0].ToString();

            string sql3 = "select MaterialType_Name from material_type_table where MaterialType_ID = " + 3;
            materialTable = SqlHelper.ExecuteDataTable(sql3);
            materialThree.Content = materialTable.Rows[0][0].ToString();

            string sql4 = "select MaterialType_Name from material_type_table where MaterialType_ID = " + 4;
            materialTable = SqlHelper.ExecuteDataTable(sql4);
            materialFour.Content = materialTable.Rows[0][0].ToString();

            string sql5 = "select MaterialType_Name from material_type_table where MaterialType_ID = " + 5;
            materialTable = SqlHelper.ExecuteDataTable(sql5);
            materialFive.Content = materialTable.Rows[0][0].ToString();

            string sql6 = "select MaterialType_Name from material_type_table where MaterialType_ID = " + 6;
            materialTable = SqlHelper.ExecuteDataTable(sql6);
            materialSix.Content = materialTable.Rows[0][0].ToString();

            string sql7 = "select MaterialType_Name from material_type_table where MaterialType_ID = " + 7;
            materialTable = SqlHelper.ExecuteDataTable(sql7);
            materialSeven.Content = materialTable.Rows[0][0].ToString();

            string sql8 = "select MaterialType_Name from material_type_table where MaterialType_ID = " + 8;
            materialTable = SqlHelper.ExecuteDataTable(sql8);
            materialEight.Content = materialTable.Rows[0][0].ToString();
        }

        DataTable materialTable1;
        private void getMaterialNum()
        {
            string sql1 = "select Material_Number from material_using_table where MaterialType_ID = 1";
            materialTable1 = SqlHelper.ExecuteDataTable(sql1);
            materialNumOne.Content = materialTable1.Rows[0][0].ToString();

            string sql2 = "select Material_Number from material_using_table where MaterialType_ID = 2";
            materialTable1 = SqlHelper.ExecuteDataTable(sql2);
            materialNumTwo.Content = materialTable1.Rows[0][0].ToString();

            string sql3 = "select Material_Number from material_using_table where MaterialType_ID = 3";
            materialTable1 = SqlHelper.ExecuteDataTable(sql3);
            materialNumThree.Content = materialTable1.Rows[0][0].ToString();

            string sql4 = "select Material_Number from material_using_table where MaterialType_ID = 4";
            materialTable1 = SqlHelper.ExecuteDataTable(sql4);
            materialNumFour.Content = materialTable1.Rows[0][0].ToString();

            string sql5 = "select Material_Number from material_using_table where MaterialType_ID = 5";
            materialTable1 = SqlHelper.ExecuteDataTable(sql5);
            materialNumFive.Content = materialTable1.Rows[0][0].ToString();

            string sql6 = "select Material_Number from material_using_table where MaterialType_ID = 6";
            materialTable1 = SqlHelper.ExecuteDataTable(sql6);
            materialNumSix.Content = materialTable1.Rows[0][0].ToString();

            string sql7 = "select Material_Number from material_using_table where MaterialType_ID = 7";
            materialTable1 = SqlHelper.ExecuteDataTable(sql7);
            materialNumSeven.Content = materialTable1.Rows[0][0].ToString();

            string sql8 = "select Material_Number from material_using_table where MaterialType_ID = 8";
            materialTable1 = SqlHelper.ExecuteDataTable(sql8);
            materialNumEight.Content = materialTable1.Rows[0][0].ToString();
        }

        DataTable materialTable2;
        private void getMaterialImage()
        {
            string sql1 = "select MaterialImage from material_using_table where MaterialType_ID = 1";
            materialTable2 = SqlHelper.ExecuteDataTable(sql1);
            BitmapImage bi1 = new BitmapImage();
            bi1.BeginInit();
            bi1.UriSource = new Uri(@materialTable2.Rows[0][0].ToString(), UriKind.Absolute);
            bi1.EndInit();
            materialImgOne.Source = bi1;

            string sql2 = "select MaterialImage from material_using_table where MaterialType_ID = 2";
            materialTable2 = SqlHelper.ExecuteDataTable(sql2);
            BitmapImage bi2 = new BitmapImage();
            bi2.BeginInit();
            bi2.UriSource = new Uri(@materialTable2.Rows[0][0].ToString(), UriKind.Absolute);
            bi2.EndInit();
            materialImgTwo.Source = bi2;

            string sql3 = "select MaterialImage from material_using_table where MaterialType_ID = 3";
            materialTable2 = SqlHelper.ExecuteDataTable(sql3);
            BitmapImage bi3 = new BitmapImage();
            bi3.BeginInit();
            bi3.UriSource = new Uri(@materialTable2.Rows[0][0].ToString(), UriKind.Absolute);
            bi3.EndInit();
            materialImgThree.Source = bi3;

            string sql4 = "select MaterialImage from material_using_table where MaterialType_ID = 4";
            materialTable2 = SqlHelper.ExecuteDataTable(sql4);
            BitmapImage bi4 = new BitmapImage();
            bi4.BeginInit();
            bi4.UriSource = new Uri(@materialTable2.Rows[0][0].ToString(), UriKind.Absolute);
            bi4.EndInit();
            materialImgFour.Source = bi4;

            string sql5 = "select MaterialImage from material_using_table where MaterialType_ID = 5";
            materialTable2 = SqlHelper.ExecuteDataTable(sql5);
            BitmapImage bi5 = new BitmapImage();
            bi5.BeginInit();
            bi5.UriSource = new Uri(@materialTable2.Rows[0][0].ToString(), UriKind.Absolute);
            bi5.EndInit();
            materialImgFive.Source = bi5;

            string sql6 = "select MaterialImage from material_using_table where MaterialType_ID = 6";
            materialTable2 = SqlHelper.ExecuteDataTable(sql6);
            BitmapImage bi6 = new BitmapImage();
            bi6.BeginInit();
            bi6.UriSource = new Uri(@materialTable2.Rows[0][0].ToString(), UriKind.Absolute);
            bi6.EndInit();
            materialImgSix.Source = bi6;

            string sql7 = "select MaterialImage from material_using_table where MaterialType_ID = 7";
            materialTable2 = SqlHelper.ExecuteDataTable(sql7);
            BitmapImage bi7 = new BitmapImage();
            bi7.BeginInit();
            bi7.UriSource = new Uri(@materialTable2.Rows[0][0].ToString(), UriKind.Absolute);
            bi7.EndInit();
            materialImgSeven.Source = bi7;

            string sql8 = "select MaterialImage from material_using_table where MaterialType_ID = 8";
            materialTable2 = SqlHelper.ExecuteDataTable(sql8);
            BitmapImage bi8 = new BitmapImage();
            bi8.BeginInit();
            bi8.UriSource = new Uri(@materialTable2.Rows[0][0].ToString(), UriKind.Absolute);
            bi8.EndInit();
            materialImgEight.Source = bi8;
        }

        private void anaconda_Click(object sender, RoutedEventArgs e)
        {
            string anaconda_path = System.Configuration.ConfigurationManager.AppSettings["app_anaconda"];
            //        System.Diagnostics.Process.Start(@arduino_path);
            try
            {
                Process scratch = new Process();
                scratch.StartInfo.FileName = anaconda_path;
                scratch.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
                scratch.Start();
                scratch.WaitForExit();
                scratch.Close();
                GC.Collect();
            }
            catch (Exception)
            {
            }

        }
    }
}
